<!doctype html>
<html lang="zh-CH">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	{{--<meta name="viewport" content="width=device-width, initial-scale=1">--}}
	<title>木投网--注册</title>
	<link rel="stylesheet" href="/resource/css/mt_index.css">
	<link rel="stylesheet" href="/resource/css/mt_login.css">
</head>
<body>
<div class="login-head register-head">
	<div class="main">
		<div class="logo">
			<a href="/"><img src="/resource/img/logo.png" alt=""></a>
			<span>欢迎注册</span>
		</div>
	</div>
</div>
<div class="register-body main">
	<div class="left">
		<form action="/depose_register" method="post" class="form" onsubmit="return check_all()">
			<div class="form-group">
				<label for=""><i>*</i>手机号</label>
				<input type="text" id="mobile" name="mobile" onblur="check_mobile()" class="form-control" placeholder="请输入正确的手机号码">
				<i class="i i-tel"></i>
				<span id="t_mobile">不能为空</span>
			</div>
			<div class="form-group form-code">
				<label for=""><i>*</i>验证码</label>
				<input type="text" class="form-control"  name="captcha" id="captcha" onblur="check_captcha()"><span id="t_captcha">验证码错误</span>
				<div style="margin-left: 8px;float:left;">
					<img onclick="this.src='/captcha?'+ Math.random()"  src="/captcha" style="width:102px;height:38px;">
				</div>
			</div>
			<div class="form-group form-code">
				<label for=""><i>*</i>手机验证码</label>
				<input type="text" class="form-control" onblur="check_news()" id="news_captcha" placeholder="短信验证码">
				<button type="button" class="btn-code btn-code-zeor" id="f_captcha">获取验证码</button>
				<span id="t_news">请输入</span>
			</div>
			<div class="form-group">
				<label for=""><i>*</i>设置密码</label>
				<input type="password" id="pwd" onblur="check_pwd()" name="password" class="form-control" placeholder="请输入密码">
				<i class="i i-pass"></i>
				<span id="t_pwd">不能为空</span>
			</div>
			<div class="form-group">
				<label for=""><i>*</i>姓名</label>
				<input type="text" class="form-control" onblur="check_username()" name="user_name" id="username" placeholder="您的姓名">
				<i class="i i-name"></i>
				<span id="t_username"></span>
			</div>
			<div class="form-group">
				<label for=""><i>*</i>公司名称</label>
				<input type="text" class="form-control" onblur="check_corporation()" id="corporation" name="corporation"  placeholder="您的公司名称">
				<i class="i i-company"></i>
				<span id="t_corporation"></span>
			</div>
			<div class="form-group form-left">
				<input type="checkbox" onclick="check_agree()" id="agree" checked="checked"> 我已阅读并同意
				<a href="javascript:;" class="a-agree">《木投网会员协议》</a>
				<span id="t_agree"></span>
			</div>
			<button type="submit" class="btn-login">立即注册</button>
		</form>
	</div>
	<div class="right">
		<div class="reg-top">
			<div class="til">已有木投网帐号？</div>
			<p>登录木投网，即可免费查看或在线购买全国便宜的木材资源及木材商品，也可以免费将您的资源发布到木投网。</p>
			<a href="javascript:;">登录</a>
		</div>
		<div class="reg-bot">
			<div class="til">有任何问题请联系客服</div>
			<div class="tel">客服电话<br/><span>400-036-7917</span></div>
		</div>
	</div>
</div>
<div class="login-foot register-foot main">
	<div class="foot-info">
		<ul>
			<li><a href="javascript:;">关于我们</a><span>|</span></li>
			<li><a href="javascript:;">法律声明</a><span>|</span></li>
			<li><a href="javascript:;">诚聘英才</a><span>|</span></li>
			{{--<li><a href="javascript:;">投资洽谈</a><span>|</span></li>--}}
			<li><a href="javascript:;">联系我们</a><span>|</span></li>
			{{--<li><a href="javascript:;">常见问题</a></li>--}}
		</ul>
		<p>北京木投网科技有限公司 京ICP备15043001   Copyright © 2016  Mutouw.com 版权所有</p>
	</div>
</div>	

<script src="/resource/js/jquery-1.11.3.min.js"></script>
<script src="/resource/js/mt_index.js"></script>
<script>
	//验证用户名
/*	function check_user() {
		var username = document.getElementById('user_name').value;
		var reg = /^[\u4E00-\u9FFF\w]+$/;
		var status = false;
		if(username){
			if(username.length<10){
				if (reg.test(username)) {
					var ajax = new XMLHttpRequest();
					ajax.onreadystatechange = function () {
						if (ajax.readyState == 4) {
							if (ajax.responseText == 0) {
								document.getElementById("t_name").innerHTML = "<span style='color:green'>√</span>";
								status = true
							} else {
								document.getElementById("t_name").innerHTML = "<span style='color:red'>用户名已存在</span>";
							}
						}
					}
					//与服务器建立连接
					ajax.open('post', '/js_verify_register', false);
					ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
					//处理请求
					ajax.send('username=' + username);
					return status
				} else {
					document.getElementById('t_name').innerHTML = "<span style='color:red'>用户名有误</span>";
					return false
				}
			}else{
				document.getElementById('t_name').innerHTML = "<span style='color:red'>10个字符以内</span>";
				return false
			}
		}else{
			document.getElementById('t_name').innerHTML = "<span style='color:red'>*</span>";
			return false
		}

	}*/
	//验证密码
	function check_pwd(){
		var pwd = $('#pwd').val();
		var reg=/^\w{6,16}$/;
		$("#t_pwd").show();
		if(pwd){
			if(reg.test(pwd)) {
				$("#t_pwd").hide();
				return true
			}else{
				$("#t_pwd").html("密码长度六位到十六位");
				return false
			}
		}else{
			$("#t_pwd").html("*");
			return false
		}
	}

	/*function check_confirm(){
		var pwd = document.getElementById('pwd').value;
		var confirm_pwd = document.getElementById('confirm_pwd').value;
		if(confirm_pwd){
			if(pwd==confirm_pwd){
				document.getElementById('t_confirm').innerHTML = "<span style='color:green'>√</span>"
				return true
			}else{
				document.getElementById('t_confirm').innerHTML = "<span style='color:red'>俩次输入密码不一致</span>"
				return false
			}
		}else{
			document.getElementById('t_confirm').innerHTML = "<span style='color:red'>*</span>"
			return false
		}

	}*/

	//验证手机号
	function check_mobile(){
		var mobile = document.getElementById('mobile').value;
		var reg = /^1[34578]\d{9}$/;
		var status = false;
		$("#t_mobile").show();
		if(mobile){
			if(reg.test(mobile)){
				var ajax = new XMLHttpRequest();
				ajax.onreadystatechange = function () {
					if (ajax.readyState == 4) {
						if (ajax.responseText == 0) {
							$("#t_mobile").hide();
							status=true
						} else {
							$("#t_mobile").html("该手机号已经注册");
						}
					}
				}
				//与服务器建立连接
				ajax.open('post', '/js_verify_register', false);
				ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
				//处理请求
				ajax.send('mobile=' + mobile);
				return status;
			}else{
				$('#t_mobile').html("请输入正确的手机号");
				return false
			}
		}else{
			$("#t_mobile").html("请输入");
			return false
		}
	}
	//验证码验证
	function check_captcha(){
		var captcha =  document.getElementById('captcha').value;
		var status = false;
		if(captcha){
			var ajax = new XMLHttpRequest();
			ajax.onreadystatechange = function () {
				if (ajax.readyState == 4) {
					if (ajax.responseText == 1) {
						$("#t_captcha").hide();
						status = true
					} else {
						$("#t_captcha").show();
					}
				}
			}
			//与服务器建立连接
			ajax.open('post', '/js_verify_register', false);
			ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			//处理请求
			ajax.send('captcha=' + captcha);
			return status
		}else{
			return false;
		}
	}

	//获取短信验证码

	$('#f_captcha').bind('click',function foo(){
		var mobile = document.getElementById('mobile').value;
		var reg = /^1[34578]\d{9}$/;
		$("#t_news").show();
		if(reg.test(mobile)) {
			if(check_mobile()){
				if(check_captcha()) {
					var wait = 60;
					var int = function fetch_captcha() {
						if (wait == 0) {
							$("#f_captcha").bind("click", foo);
							$('#f_captcha').html('获取验证码').addClass('btn-code-zeor');
							clearInterval(a)
							wait = 60;
						}
						else {
							$('#f_captcha').unbind("click", foo);
							$('#f_captcha').html("重新发送(" + wait + ")").removeClass('btn-code-zeor');
							wait--;
						}
					}
					var a = setInterval(int, 1000);
					$.ajax({
						url: "/verify_news",
						type: "POST",
						data: "mobile=" + mobile,
						success: function (msg) {
							if (msg == 10000) {
								$("#t_news").html("验证码发送成功,10分钟内输入有效");
							}else if(msg == 160040){
								$("#t_news").html("您当日验证码发送次数过多");
								window.clearInterval(a);//停止计时器
								$(".form-code span.code").removeAttr("disabled").css('cursor','pointer');//启用按钮
								$(".form-code span.code").html("获取短信验证码");
								return false;
							}else{
								$("#t_news").html("验证码发送错误");
								window.clearInterval(a);//停止计时器
								$(".form-code span.code").removeAttr("disabled").css('cursor','pointer');//启用按钮
								$(".form-code span.code").html("获取短信验证码");
								return false;
							}
						}
					});
				}else{
					$("#t_captcha").show();
					return false
				}
			}else{
				document.getElementById('t_mobile').innerHTML = "<span style='color:red'>该手机号已经注册</span>"
				return false
			}
		}else{
			$("#t_news").html("请输入正确的手机号");
			return false
		}
	})


	//短信验证
	function check_news(){
		var news_captcha = document.getElementById('news_captcha').value;
		var mobile = document.getElementById('mobile').value;
		$("#t_news").show();
		var status = false;
		if(news_captcha){
			var ajax = new XMLHttpRequest();
			ajax.onreadystatechange = function () {
				if (ajax.readyState == 4) {
					if (ajax.responseText == 1) {
						$("#t_news").hide();
						status = true
					}else if(ajax.responseText == 2){
						$("#t_news").html("验证码已过期");
					}else{
						$("#t_news").html("验证码错误");
					}
				}
			}
			//与服务器建立连接
			ajax.open('post', '/js_verify_register', false);
			ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			//处理请求
			ajax.send('news_captcha=' + news_captcha + '&mobile=' +mobile);
			return status
		}else{
			document.getElementById('t_news').innerHTML = "<span style='color:red'>*</span>";
			return false;
		}

	}

	function check_username() {
		var username = $('#username').val();
		$("#t_username").show();
		if (username){
			$("#t_username").hide();
				return true
			} else {
				$("#t_username").html("请填写");
				return false
			}
		}

	function check_corporation() {
		var corporation = $('#corporation').val();
		$("#t_corporation").show();
		if (corporation){
			$("#t_corporation").hide();
			return true
		} else {
			$("#t_corporation").html("请填写");
			return false
		}
	}


	//复选框
	function check_agree()
	{
		$('#t_agree').show();
		var agree = document.getElementById('agree');
		if(agree.checked){
			$("#t_agree").html("已阅读");
			return true
		}else{
			$("#t_agree").html("请阅读");
			return false
		}
	}

	//检测全部
	function check_all(){
		return (check_pwd()&&check_mobile()&&check_news()&&check_agree()&&check_corporation()&&check_username())
	}

</script>
</body>
</html>